package com.letv.android.client.episode.adapter;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import com.letv.android.client.episode.DetailPlayFragmentMannager;
import com.letv.android.young.client.R;

public class DetailPlayPagerAdapterPlayerLibs extends FragmentStatePagerAdapter { // 

	private DetailPlayFragmentMannager fragmentMannager ;
	
	private FragmentManager fm ;
	
	private Context context;
	
	protected static String[] TEXTS ;
    public static String FORTH_VIP_MEMBER;
    public static String FORTH_INIT_TITLE;

    private boolean isVideoNormal = true;

    public DetailPlayPagerAdapterPlayerLibs(Context context, FragmentManager fm) {
		super(fm);
		this.context = context;
		this.fm = fm ;
	}
	
    public void setParams(boolean videoNormal,int showMode, boolean isVipFlag) {
        this.isVideoNormal = videoNormal;
        TEXTS = null;
        if (isVideoNormal) {
            try{
            if (showMode == 0) {
                TEXTS = context.getResources()
                        .getStringArray(R.array.detailplay_half_tabs_normal);
            } else if (showMode == 1) {
                TEXTS = context.getResources()
                        .getStringArray(R.array.detailplay_half_tabs_normal_two);
            } else if (showMode == 2) {
                TEXTS = context.getResources()
                        .getStringArray(R.array.detailplay_half_tabs_normal_three);
            } else if (showMode == 3) {
                TEXTS = context.getResources()
                        .getStringArray(R.array.detailplay_half_tabs_normal_vip);
            } else {
                TEXTS = context.getResources()
                        .getStringArray(R.array.detailplay_half_tabs_unnormal);
            }
            }catch(NullPointerException e){e.printStackTrace();}
            /*
             * 如果是会员影片，第四栏显示为会员 5.9 第三栏显示会员
             */
            if (isVipFlag) {
                TEXTS[2] = context.getResources().getString(R.string.vip_tag);
            }
        } else {
            TEXTS = context.getResources().getStringArray(R.array.detailplay_half_tabs_unnormal);
        }
        fragmentMannager = new DetailPlayFragmentMannager(fm, isVideoNormal);
    }
    
	@Override
	public Fragment getItem(int pos) {		
		return fragmentMannager.newInstance(pos);
	}

	@Override  
	public int getItemPosition(Object object) {  
	    return POSITION_NONE;  
	}
	
	@Override
	public int getCount() {
		return TEXTS == null ? 0 : TEXTS.length;
	}

	@Override
	public CharSequence getPageTitle(int position) {
		return TEXTS[position];
	}
}


/*
package com.letv.android.client.playerlibs.adatper;

import android.content.Context;
import android.support.v4.com.ledim.app.Fragment;
import android.support.v4.com.ledim.app.FragmentManager;
import android.support.v4.com.ledim.app.FragmentTransaction;
import android.support.v4.view.PagerAdapter;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

import com.letv.android.client.playerlibs.R;
import com.letv.android.client.playerlibs.utils.LogInfoPlayerLibs;

public class DetailPlayPagerAdapterPlayerLibs extends PagerAdapter{

	private static DetailPlayFragmentMannagerPlayerLibs fragmentMannager ;
	
	private FragmentManager fm ;
	
	protected static String[] TEXTS ;
    public static String FORTH_VIP_MEMBER;
    public static String FORTH_INIT_TITLE;

    private boolean isVideoNormal = true;
    FragmentTransaction fragmentTransaction;
    
    public static void initViewPager(FragmentManager fm, int viewpagerid, boolean videoNormal){
    	fragmentMannager = new DetailPlayFragmentMannagerPlayerLibs(videoNormal) ;
    	Fragment f1 = fragmentMannager.newInstance(0);
		Fragment f2 = fragmentMannager.newInstance(1);
		Fragment f3 = fragmentMannager.newInstance(2);
		Fragment f4  = null;
    	if (videoNormal){
    	    f4 = fragmentMannager.newInstance(3);
    	}
		FragmentTransaction fragmentTransaction = fm.beginTransaction();
		fragmentTransaction.add(viewpagerid, f1, "1");
		fragmentTransaction.add(viewpagerid, f2, "2");
		fragmentTransaction.add(viewpagerid, f3, "3");
		if (videoNormal){
			fragmentTransaction.add(viewpagerid, f4, "4");
		}
		
		fragmentTransaction.hide(f1);
		fragmentTransaction.hide(f2);
		fragmentTransaction.hide(f3);
		if (videoNormal){
			fragmentTransaction.hide(f4);
		}
		
		fragmentTransaction.commitAllowingStateLoss();
		fm.executePendingTransactions();
		
	}

	public DetailPlayPagerAdapterPlayerLibs(Context context, FragmentManager fm, boolean videoNormal,int showMode) {
		this.fm = fm ;
        this.isVideoNormal = videoNormal;
        TEXTS = null;
        if(isVideoNormal){
            if(showMode == 0){
                TEXTS = context.getResources().getStringArray(R.array.detailplay_half_tabs_normal);
            }else if(showMode == 1){
                TEXTS = context.getResources().getStringArray(R.array.detailplay_half_tabs_normal_two);
            }else if(showMode == 2){
                TEXTS = context.getResources().getStringArray(R.array.detailplay_half_tabs_normal_three);
            }else {
                TEXTS = context.getResources().getStringArray(R.array.detailplay_half_tabs_unnormal);
            }
            FORTH_VIP_MEMBER = context.getResources().getString(R.string.vip_tag);
            FORTH_INIT_TITLE = TEXTS[3];
        }else{
            TEXTS = context.getResources().getStringArray(R.array.detailplay_half_tabs_unnormal);
        }
	}

//	@Override
//	public Fragment getItem(int pos) {
//		return fragmentMannager.newInstance(pos);
//	}

	@Override
	public int getCount() {
		return TEXTS == null ? 0 : TEXTS.length;
	}

	@Override
	public CharSequence getPageTitle(int position) {
		return TEXTS[position];
	}

    public void setForthVipPageTitle() {

        if(TEXTS.length> 3) {

            TEXTS[3] = FORTH_VIP_MEMBER;
        }
    }

    public void setForthNormalPageTitle() {

        if(TEXTS.length> 3) {

            TEXTS[3] = FORTH_INIT_TITLE;
        }
    }

    public String getCurForthPageTitle() {

        if(TEXTS.length> 3) {

            return TEXTS[3];
        }
        return "";
    }

	public void format(){
		fragmentMannager.destroy(fm);
		fragmentMannager = null ;
	}

	@Override
	public boolean isViewFromObject(View view, Object object) {
		return ((Fragment) object).getView() == view;
	}
	
	@Override
	public Object instantiateItem(View container, int position) {
		if (fragmentTransaction == null){
			fragmentTransaction = fm.beginTransaction();
		}
		
		Fragment f = fragmentMannager.newInstance(position);
		fragmentTransaction.show(f);
		f.setUserVisibleHint(f == mCurrentPrimaryItem);
		return f;
	}
	
	Fragment mCurrentPrimaryItem;

	@Override
	public void setPrimaryItem(ViewGroup container, int position,
			Object object) {
		Fragment fragment = (Fragment) object;
		if (mCurrentPrimaryItem != fragment) {
			LogInfo.log("setPrimaryItem", "mCurrentPrimaryItem != fragment");
			if (mCurrentPrimaryItem != null) {
				mCurrentPrimaryItem.setUserVisibleHint(false);
			}
			if (fragment != null) {
				fragment.setUserVisibleHint(true);
			}
			mCurrentPrimaryItem = fragment;
		}
	}
	
	@Override
    public void finishUpdate(ViewGroup container) {
		LogInfo.log("finishUpdate", "finishUpdate finishUpdate: ");
        if (fragmentTransaction != null) {
        	fragmentTransaction.commitAllowingStateLoss();
        	fragmentTransaction = null;
        	fm.executePendingTransactions();
        }
    }
	
	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		LogInfo.log("destroyItem", "destroyItem position: " + position);
		if (fragmentTransaction == null){
			fragmentTransaction = fm.beginTransaction();
		}
		fragmentTransaction.hide(((Fragment)object));
	}
}
*/